import request from '@/utils/request';
import { AxiosPromise } from 'axios';
import { AdmCarStoreVO, AdmCarStoreForm, AdmCarStoreQuery, AdmCarStoreDto } from '@/api/general/administration/car/store/types';

/**
 * 查询车辆登记列表
 * @param query
 * @returns {*}
 */

export const listAdmCarStore = (query?: AdmCarStoreQuery): AxiosPromise<AdmCarStoreVO[]> => {
  return request({
    url: '/system/admCarStore/list',
    method: 'get',
    params: query
  });
};

/**
 * 查询车辆登记详细
 * @param id
 */
export const getAdmCarStore = (id: string | number): AxiosPromise<AdmCarStoreVO> => {
  return request({
    url: '/system/admCarStore/' + id,
    method: 'get'
  });
};

/**
 * 新增车辆登记
 * @param data
 */
export const addAdmCarStore = (data: AdmCarStoreForm) => {
  return request({
    url: '/system/admCarStore',
    method: 'post',
    data: data
  });
};

/**
 * 修改车辆登记
 * @param data
 */
export const updateAdmCarStore = (data: AdmCarStoreForm) => {
  return request({
    url: '/system/admCarStore',
    method: 'put',
    data: data
  });
};

/**
 * 删除车辆登记
 * @param id
 */
export const delAdmCarStore = (id: string | number | Array<string | number>) => {
  return request({
    url: '/system/admCarStore/' + id,
    method: 'delete'
  });
};

/**
 * 查询车辆登记列表
 * @param query
 * @returns {*}
 */

export const queryCanInfo = (query?: AdmCarStoreDto): AxiosPromise<AdmCarStoreDto[]> => {
  return request({
    url: '/system/admCarStore/queryList',
    method: 'post',
    data: query
  });
};

/**
 * 导入物品 Excel
 * @param file 文件对象
 * @param bookStoreBo 额外参数对象
 */
export const importCar = (file: File, bookStoreBo: any): AxiosPromise<void> => {
  const formData = new FormData();
  formData.append('file', file);
  formData.append('data', JSON.stringify(bookStoreBo));

  return request({
    url: '/system/admCarStore/import',
    method: 'post',
    data: formData,
    headers: { 'Content-Type': 'multipart/form-data' }
  });
};